﻿using Edutainment.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Edutainment
{
	/// <summary>
	/// Interaktionslogik für Sortieralgorithmen.xaml
	/// </summary>
	public partial class Sortieralgorithmen : UserControl, IStatisticInterface
	{
        SortAlgorithm sortForStatistic;

		public Sortieralgorithmen()
		{
			this.InitializeComponent();
                        
		}
      
        public string sortTitle { get{
            return this.sortTitleProperty;
        } set{
            this.titleName.Text = value;
            this.getCorrectSortAlgorithm();
        } }

        public string sortTitleProperty
        {
            get { return (string)GetValue(sortTitleDependency); }
            set { SetValue(sortTitleDependency, value); }
        }
        public static readonly DependencyProperty sortTitleDependency =
       
            DependencyProperty.Register("sortTitleProperty", typeof(string), typeof(Sortieralgorithmen));
      
        public Sortieralgorithmen(String titleName)
        {
            this.InitializeComponent();
            this.titleName.Text = titleName;

        }

        public void updateGui()
        {
            if (sortForStatistic != null)
            {
                string exercises = String.Format("{0}/{1}", sortForStatistic.solvedExercises, sortForStatistic.exercises);
                string exams = String.Format("{0}/{1}",sortForStatistic.solvedExams, sortForStatistic.exams);

                exercisesCount.Text = exercises;
                examsCount.Text = exams;
            }
        }

        private void getCorrectSortAlgorithm()
        {
            string sort = this.titleName.Text;
            AppManager mngr = ((App)App.Current).getAppManager();
            SortationController sCtlr = mngr.sortController;
            if (sort != null)
            {
                if (sort.Contains("Bubble"))
                {
                    sortForStatistic = sCtlr.bubbleSort;
                    sortForStatistic.addObserverForStatisticUpdates(this);
                }
                else if (sort.Contains("Merge"))
                {
                    sortForStatistic = sCtlr.mergeSort;
                    sortForStatistic.addObserverForStatisticUpdates(this);
                }
            }
        }
	}
}